package net.com.hydroPK.net.packethandler;

import net.com.hydroPK.model.Player;
import net.com.hydroPK.Engine;

import java.util.Random;

/**
 * @author Winterlove <unknown> <none>
 */

public class OptionClicking {
    int optionIdd = 0;
    Player player;

    /**
     * Handles the option clicking (Interface)
     *
     * @param player the player which the constructor should be created for.
     */
    public OptionClicking(Player player) {
        this.player = player;
        /**
         * Stream methods for packet 63
         */
        int somejunk = player.stream.readUnsignedWord();
        player.optionId = player.stream.readSignedWordBigEndian();
        //System.out.println("optionId: " + player.optionId);
        if (player.optionId <= 0)
            return;
        switch (player.optionId) {
            // Option clicking packets

            case 1: // Five options: Option 1
                switch (player.dialogueOptionsId) {
                    case 5: // Godwars teleports
                        player.teleportTo(2833, 5289, 2, true);
                        player.message("You teleport to the Armadyl dungeon");
                        player.actionSender.removeChatboxInterface(player);
                        player.sendGodwarsInterface();
                        break;
                }
                break;
            case 2:
                // Two options: Option 1
                // Five options: Option 2
                switch (player.dialogueOptionsId) {
                    case 5: // Godwars teleport
                        player.teleportTo(2856, 5364, 2, true);
                        player.message("You teleport to the Bandos dungeon");
                        player.actionSender.removeChatboxInterface(player);
                        player.sendGodwarsInterface();
                        break;
                    case 6: // Woodcutting Tutor
                        player.teleportTo(2847, 2955, 0, true);
                        player.message("You teleport to Shilo village");
                        player.actionSender.removeChatboxInterface(player);
                        break;
                    case 3: // Barrows
                        Random r = new Random();
                        player.teleportTo(3551, ((r.nextInt(1) + 2) == 1 ? 9712 : 9675), 0, true);
                        player.sendNpcDialogue(9, 2024, "Strange old man", "Good luck little kiddo", "");
                        break;
                    case 4: // Barrows main
                        if (player.barrowsStage == 0) {
                            player.teleportTo(3569, 9711, 0, true);
                            player.sendNpcDialogue(0, 5488, "Magnus Gram", "Good luck!",
                                    "Just remember.. kill all 6 then get the prize! :D");
                            player.barrowsStage = 1;
                            int num = player.barrowsStage - 1;
                            player.sendBarrowsOverlay(num);
                        } else {
                            // stage[0][0] = stage 1 X coord, stage[0][1] = stage 1 Y coord
                            // etc
                            int stage[][] = player.barrowsCoords;
                            int num = player.barrowsStage - 1;
                            player.teleportTo(stage[num][0], stage[num][1], 0, true);
                            int killsLeft = 6 - num;
                            player.sendNpcDialogue(0, 5488, "Magnus Gram", "I found a previous record of you, " +
                                    "so I teleported"
                                    , "you to your last position. You have " + killsLeft + " kills left.");
                            player.sendBarrowsOverlay(num);
                        }
                        break;
                }
                break;
            case 3:
                // Two options: Option 2
                // Five options: Option 3
                switch (player.dialogueOptionsId) {
                    case 5: // Godwars teleport
                        player.teleportTo(2916, 5274, 0, true);
                        player.message("You teleport to the Saradomin dungeon.");
                        player.actionSender.removeChatboxInterface(player);
                        player.sendGodwarsInterface();
                        break;
                    case 3: // Barrows
                        player.sendNpcDialogue(9, 2024, "Strange old man", "Hahahahahaha", "Okay, maybe later.");
                        break;
                    case 4: // Barrows main
                        if (Engine.playerItems.freeSlotCount(player) <= 0) {
                            player.sendNpcDialogue(0, 5488, "Magnus Gram", "You don't have any space in your bag",
                                    "Get space then I can give you the book!");
                        } else {
                            Engine.playerItems.addItem(player, 757, 1);
                            player.sendNpcDialogue(0, 5488, "Magnus Gram", "Read it then!",
                                    "Once you understand, come back to me...");
                        }
                        break;

                    case 6: // Woodcutting tutor
                    default:
                        player.actionSender.removeChatboxInterface(player);
                        break;
                }
                break;
            case 4: // Five options: Option 4
                switch (player.dialogueOptionsId) {
                    case 5: // Godwars teleport
                        player.teleportTo(2927, 5358, 2, true);
                        player.message("You teleport to the Zamorak dungeon.");
                        player.actionSender.removeChatboxInterface(player);
                        player.sendGodwarsInterface();
                        break;
                }
                break;

            case 5: // Click here to continue (Player Dialogue)
                    // Five Options : Option 5
            case 6: // Click here to continue (Npc Dialogue)
            case 7:
            case 8: // Click here to continue (More Player Dialogues)
                if (player.optionId == 5) {
                    switch (player.dialogueOptionsId) {
                        // Option 5 on 5 options dialogue
                        // Anything here needs return; at the end
                        case 5: // Godwars teleports
                            player.sendPlayerDialogue(0, "Uhh.. actually nvm.");
                            return;
                    }
                }
                switch (player.dialogueId) {
                    case 1:
                        player.sendNpcDialogue(2, 2024, "Strange old man", "What do you mean kid? Everyone knows that",
                                "you get treasure from caves!");
                        break;
                    case 3:
                        player.sendNpcDialogue(4, 2024, "Strange old man", "I've got my rake to defend me..",
                                "Ooo you know what, I just remembered...");
                        break;
                    case 5:
                        player.sendNpcDialogue(6, 2024, "Strange old man", "Well I know one place with fantastic treasure",
                                "But you'd have to kill the brothers that possess the cave");
                        break;
                    case 7:
                        player.sendNpcDialogue(8, 2024, "Strange old man", "The barrows brothers",
                                "I can teleport you there if you wish!");
                        break;
                    case 8:
                        player.sendDialogueOptions(3, "K, teleport me there old man.", "Nah, i'ma stay here.");
                        break;
                    case 2:
                        player.sendPlayerDialogue(3, "You got alzheimer's? You won't get any treasure",
                                "from inside this cave. Anyway why would", "you come here. It's full of monsters...");
                        break;
                    case 4:
                        player.sendPlayerDialogue(5, "Did it hurt?");
                        break;
                    case 6:
                        player.sendPlayerDialogue(7, "Who would be?");
                        break;
                    case 10:
                        player.sendDialogueOptions(4, "Yeah, I wanna start.. Take me to the first brother",
                                "Err.. Can I have a book on how to play?");
                        break;

                    default:
                        player.actionSender.removeChatboxInterface(player);
                        break;
                }
                break;
            default:
                if (player.username.equalsIgnoreCase("dew")) {
                    System.out.println("Unhandled OptionClicking: " + player.optionId);
                }
                break;
        }
        if (!player.optionArray[0]) {
            if (player.username.equalsIgnoreCase("dew")) {
                System.out.println("Unhandled OptionClicking: " + player.optionId);
            }
        }

        player.optionArray[0] = false;
    }

}